package com.qf.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 孙亚梅
 * @version V1.0
 * @Project bookApp-homework
 * @Package com.qf.servlet
 * @Description:
 * @Date 2022/5/17 10:23
 */
@WebServlet(name = "regist",urlPatterns = "/registServlet")
public class RegistServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1:设置编码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        //2：获取页面传入的参数
        String name = req.getParameter("name");

        //3：判断以及实现业务
        String result = null;
        if (name.equals("root") || name.equals("admin")){
            //我们定义2代表该用户以及存在
            result = "2";
        }else{
            //定义该用户可以注册
            result = "1";
        }
//4:通过响应写数据到页面
        resp.getWriter().write(result);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
